﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Media.Media3D;


namespace Game3D
{
    internal class GameMesh_old
    {
        public int Rotation { get; set; }
        public Shape Type { get; set; }
        public ModelVisual3D Model { get; set; }
        public GeometryModel3D GeometryModel { get; set; }
        public MeshGeometry3D Mesh { get; set; }
        
        public Transform3DGroup Transformations { get; set; }
        private RotateTransform3D RotateTransformation { get; set; }
        private AxisAngleRotation3D AxisAngleTransformation { get; set; }

        public GameMesh_old()
        {
            Model = new ModelVisual3D();
            GeometryModel = new GeometryModel3D();
            Mesh = new MeshGeometry3D();
            RotateTransformation = new RotateTransform3D();
            AxisAngleTransformation = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 0);
            Transformations = new Transform3DGroup();

            Model.Content = GeometryModel;
            GeometryModel.Geometry = Mesh;
            Model.Transform = Transformations;

            RotateTransformation.Rotation = AxisAngleTransformation;
            Transformations.Children.Add(RotateTransformation);
            Model.Transform = Transformations;
        }

        public GameMesh_old(int rotationToApply, Shape typeToApply)
        {
            Rotation = rotationToApply;
            Type = typeToApply;

            Model = new ModelVisual3D();
            GeometryModel = new GeometryModel3D();
            Mesh = new MeshGeometry3D();

            Model.Content = GeometryModel;
            GeometryModel.Geometry = Mesh;

            Mesh.Positions = GameMeshGrid.MeshGrid;
            Mesh.Normals = GameMeshNormals.MeshNormals;

            Mesh.TriangleIndices = GameShapes.ResolveShape(Type);
            GeometryModel.Material = new DiffuseMaterial(GameShapeColors.ResolveColor(Type));

            Rotation = rotationToApply;
            RotateTransformation = new RotateTransform3D();
            AxisAngleTransformation = new AxisAngleRotation3D(new Vector3D(0,0,1), Rotation);
            Transformations = new Transform3DGroup();
            RotateTransformation.Rotation = AxisAngleTransformation;
            Transformations.Children.Add(RotateTransformation);
            Model.Transform = Transformations;
        }

        public void FlushMesh()
        {
            Mesh.TriangleIndices = GameShapes.ResolveShape(Type);
            GeometryModel.Material = new DiffuseMaterial(GameShapeColors.ResolveColor(Type));
            AxisAngleTransformation.Angle = Rotation;
            Model.Transform = Transformations;
        }

    }
}
